<template>
  <div class="divBox relative">
    <el-card
      :bordered="false"
      shadow="never"
      class="ivu-mt"
      :body-style="{ padding: 0 }"
      v-hasPermi="['platform:user:page:list']"
    >
      <div class="padding-add">
        <el-form
          ref="userFrom"
          :model="userFrom"
          label-width="120px"
          label-position="right"
          @submit.native.prevent
          inline
        >
          <div class="acea-row search-form" v-if="!collapse">
            <div class="search-form-box">
              <el-form-item label="选手名称：">
                <el-input style="width: 260px" v-model="userFrom.playerName" placeholder="请输入选手名称"></el-input>
              </el-form-item>
              <el-form-item label="邮箱账号：">
                <el-input style="width: 260px" v-model="userFrom.emailAccount" placeholder="请输入邮箱账号"></el-input>
              </el-form-item>
              <el-form-item label="手机号：">
                <el-input style="width: 260px" v-model="userFrom.phone" placeholder="请输入手机号"></el-input>
              </el-form-item>
              <el-form-item label="学校/企业：">
                <el-input style="width: 260px" v-model="userFrom.schoolCompany" placeholder="请输入学校或企业名称"></el-input>
              </el-form-item>
              <!-- 添加作品审核状态字段 -->
              <el-form-item label="作品审核状态：">
                <el-select v-model="userFrom.auditStatus" placeholder="请选择" size="small" class="selWidth" clearable>
                  <el-option v-for="item in auditStatusList" :key="item.value" :label="item.label" :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
              <!-- 添加选手认证类型字段 -->
              <el-form-item label="选手认证类型：">
                <el-select v-model="userFrom.applyTypes" placeholder="请选择" size="small" class="selWidth" clearable>
                  <el-option v-for="item in applyTypesList" :key="item.value" :label="item.label" :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </div>
            <el-form-item class="search-form-sub">
              <el-button type="primary" size="small" @click="userSearchs">搜索</el-button>
              <el-button size="small" @click="reset" class="ResetSearch">重置</el-button>
              <!-- <a class="ivu-ml-8 font12 ml10" @click="collapse = !collapse">
                <template v-if="!collapse"> 展开 <i class="el-icon-arrow-down" /> </template>
                <template v-else> 收起 <i class="el-icon-arrow-up" /> </template>
              </a> -->
            </el-form-item>
          </div>
          <div v-if="collapse" class="acea-row search-form">
            <div class="search-form-box">
              <el-form-item label="选手名称：">
                <el-input style="width: 260px" v-model="userFrom.playerName" placeholder="请输入选手名称"></el-input>
              </el-form-item>
              <el-form-item label="邮箱账号：">
                <el-input style="width: 260px" v-model="userFrom.emailAccount" placeholder="请输入邮箱账号"></el-input>
              </el-form-item>
              <el-form-item label="手机号：">
                <el-input style="width: 260px" v-model="userFrom.phone" placeholder="请输入手机号"></el-input>
              </el-form-item>
              <el-form-item label="用户标签：">
                <el-select
                  v-model.trim="labelData"
                  placeholder="请选择"
                  class="selWidth"
                  clearable
                  filterable
                  multiple
                  size="small"
                >
                  <el-option
                    :value="item.id"
                    v-for="(item, index) in labelLists"
                    :key="index"
                    :label="item.name"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="消费情况：">
                <el-select v-model="userFrom.payCount" placeholder="请选择" size="small" class="selWidth" clearable>
                  <el-option value="0" label="0"></el-option>
                  <el-option value="1" label="1+"></el-option>
                  <el-option value="2" label="2+"></el-option>
                  <el-option value="3" label="3+"></el-option>
                  <el-option value="4" label="4+"></el-option>
                  <el-option value="5" label="5+"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="用户性别：">
                <el-select v-model="userFrom.sex" placeholder="请选择" size="small" class="selWidth" clearable>
                  <el-option value="" label="全部"></el-option>
                  <el-option value="0" label="未知"></el-option>
                  <el-option value="1" label="男"></el-option>
                  <el-option value="2" label="女"></el-option>
                  <el-option value="3" label="保密"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="用户身份：">
                <el-select v-model="userFrom.identity" placeholder="请选择" size="small" class="selWidth" clearable>
                  <el-option value="" label="全部"></el-option>
                  <el-option value="1" label="推广员"></el-option>
                  <el-option value="3" label="付费会员"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="时间选择：">
                <el-date-picker
                  v-model="timeVal"
                  align="right"
                  unlink-panels
                  value-format="yyyy-MM-dd"
                  format="yyyy-MM-dd"
                  size="small"
                  type="daterange"
                  placement="bottom-end"
                  placeholder="自定义时间"
                  :picker-options="pickerOptions"
                  @change="onchangeTime"
                  class="selWidth"
                />
              </el-form-item>
              <el-form-item label="注册类型：">
                <el-select v-model="userFrom.registerType" placeholder="请选择" size="small" class="selWidth" clearable>
                  <el-option v-for="item in registerTypeList" :key="item.value" :label="item.label" :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </div>
            <el-form-item class="search-form-sub">
              <el-button type="primary" size="small" @click="userSearchs">搜索</el-button>
              <el-button class="ResetSearch" size="small" @click="reset">重置</el-button>
              <a class="ivu-ml-8 font12 ml10" @click="collapse = !collapse">
                <template v-if="!collapse"> 展开 <i class="el-icon-arrow-down" /> </template>
                <template v-else> 收起 <i class="el-icon-arrow-up" /> </template>
              </a>
            </el-form-item>
          </div>
        </el-form>
      </div>
    </el-card>
    <el-card class="box-card mt14" :body-style="{ padding: '20px' }" shadow="never" :bordered="false">
      <!-- 标签页 -->
      <el-tabs class="list-tabs" v-model="activeTab" @tab-click="handleTabClick">
        <el-tab-pane label="待审核" name="1" />
        <el-tab-pane label="全部" name="all" />
        <el-tab-pane label="审核选手认证" name="audit" />
      </el-tabs>
      <!-- <div class="acea-row row-middle">
        <el-dropdown size="small">
          <el-button :disabled="!multipleSelectionAll.length">
            批量设置<i class="el-icon-arrow-down el-icon--right"></i>
          </el-button>
          <el-dropdown-menu slot="dropdown">
            <template v-if="multipleSelectionAll.length">
              <el-dropdown-item v-hasPermi="['platform:user:tag']" @click.native="setBatch('label', '', 1)"
                >批量添加标签</el-dropdown-item
              >
              <el-dropdown-item
                v-hasPermi="['platform:coupon:can:send:list', 'platform:coupon:batch:send']"
                @click.native="sendCoupon"
                >发送优惠券</el-dropdown-item
              >
              <el-dropdown-item v-hasPermi="['platform:user:gift:paid:member']" @click.native="handleGiftMembers('')"
                >赠送会员</el-dropdown-item
              >
            </template>
          </el-dropdown-menu>
        </el-dropdown>
        <div v-show="multipleSelectionAll.length" class="ml12 font12">
          已选 <span class="font-color font12"> {{ multipleSelectionAll.length }} </span>项
          <span @click="handleResetSelection" class="ml12 pointer">清空</span>
        </div>
      </div> -->
      <!-- 选手管理表格 -->
      <el-table
        v-if="activeTab !== 'audit'"
        ref="table"
        v-loading="listLoading"
        :data="tableData.data"
        size="small"
        @selection-change="handleSelectionChange"
        highlight-current-row
        class="mt20"
      >
        <!-- 原有的选手管理表格列 -->
        <el-table-column type="expand" width="40">
          <template slot-scope="props">
            <el-form label-position="left" inline class="demo-table-expand">
              <el-form-item label="首次访问：">
                <span>{{ props.row.createTime | filterEmpty }}</span>
              </el-form-item>
              <el-form-item label="近次访问：">
                <span>{{ props.row.lastLoginTime | filterEmpty }}</span>
              </el-form-item>
              <el-form-item label="标签：">
                <span>{{ props.row.tagId | tagFilter }}</span>
              </el-form-item>
              <el-form-item label="地址：">
                <span>{{ (props.row.province + props.row.city) | filterEmpty }}</span>
              </el-form-item>
              <el-form-item label="备注：" style="width: 100%; display: flex; margin-right: 10px">
                <span>{{ props.row.mark | filterEmpty }}</span>
              </el-form-item>
            </el-form>
          </template>
        </el-table-column>
        <!-- <el-table-column type="selection" width="45"></el-table-column> -->
        <el-table-column prop="euserId" label="选手id" width="70" align="center" v-if="checkedCities.includes('ID')" />
        <el-table-column label="头像" width="100" v-if="checkedCities.includes('头像')">
          <template slot-scope="scope">
            <div class="demo-image__preview line-heightOne">
              <el-image :src="scope.row.avatar" :preview-src-list="[scope.row.avatar]" fit="cover" />
            </div>
          </template>
        </el-table-column>
        <el-table-column label="选手名称" min-width="180" v-if="checkedCities.includes('姓名')">
          <template slot-scope="scope">
            <div class="acea-row row-middle">
              <span :class="scope.row.isLogoff ? 'red' : ''">{{ scope.row.playerName | filterEmpty }} </span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="联系电话" min-width="100" v-if="checkedCities.includes('联系电话')">
          <template slot-scope="scope">
            <span>{{ scope.row.phone | filterEmpty }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="emailAccount" label="邮箱" min-width="150" v-if="checkedCities.includes('余额')" />
        <el-table-column label="学校/企业" min-width="150">
          <template slot-scope="scope">
            <span v-if="scope.row.applyType === 3 && scope.row.schoolName">{{ scope.row.schoolName }}</span>
            <span v-else-if="scope.row.applyType === 2 && scope.row.companyName">{{ scope.row.companyName }}</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column prop="totalWorksCount" label="总作品数" min-width="150" />
        <el-table-column prop="pendingWorksCount" label="待审核作品数" min-width="150" />
        <el-table-column prop="approvedWorksCount" label="已通过作品数" min-width="150" />
        <el-table-column prop="rejectedWorksCount" label="已驳回作品数" min-width="150" />
        <el-table-column prop="createTime" label="注册时间" min-width="150" v-if="checkedCities.includes('积分')" />
        <el-table-column label="操作" width="60" fixed="right">
          <template slot-scope="scope">
            <a @click="onDetails(scope.row.id, scope.row)" v-if="checkPermi(['platform:user:detail'])">详情</a>
          </template>
        </el-table-column>
      </el-table>

      <!-- 审核选手认证表格 -->
      <el-table
        v-if="activeTab === 'audit'"
        v-loading="auditListLoading"
        :data="auditTableData.data"
        size="small"
        highlight-current-row
        class="mt20"
      >
        <el-table-column prop="euserId" label="用户ID" min-width="80" />
        <el-table-column prop="name" label="姓名" min-width="100">
          <template slot-scope="scope">
            <span>{{ scope.row.name | filterEmpty }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="phoneNumber" label="手机号" min-width="120">
          <template slot-scope="scope">
            <span>{{ scope.row.phoneNumber | filterEmpty }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="email" label="邮箱" min-width="150" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <span>{{ scope.row.email | filterEmpty }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="idCard" label="身份证号" min-width="150" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <span>{{ scope.row.idCard | filterEmpty }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="companyName" label="企业名称" min-width="150" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <span>{{ scope.row.companyName | filterEmpty }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="schoolName" label="学校名称" min-width="150" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <span>{{ scope.row.schoolName | filterEmpty }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="applyType" label="认证类型" min-width="100">
          <template slot-scope="scope">
            <el-tag :type="getApplyTypeTagType(scope.row.applyType)">
              {{ getApplyTypeText(scope.row.applyType) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="checkStatus" label="审核状态" min-width="100">
          <template slot-scope="scope">
            <el-tag :type="getAuditStatusTagType(scope.row.checkStatus)">
              {{ getAuditStatusText(scope.row.checkStatus) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="checkRemark" label="审核说明" min-width="150" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <span>{{ scope.row.checkRemark | filterEmpty }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="applyTime" label="报名时间" min-width="150">
          <template slot-scope="scope">
            <span>{{ scope.row.applyTime | filterEmpty }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间" min-width="150">
          <template slot-scope="scope">
            <span>{{ scope.row.createTime | filterEmpty }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200" fixed="right">
          <template slot-scope="scope">
            <a @click="handleAuditDetail(scope.row)">详情</a>
            <el-divider direction="vertical"></el-divider>
            <a
              @click="handleAudit(scope.row)"
              :class="{ 'disabled-link': isAuditCompleted(scope.row.checkStatus) }"
              :style="{ cursor: isAuditCompleted(scope.row.checkStatus) ? 'not-allowed' : 'pointer' }"
            >审核</a>
          </template>
        </el-table-column>
      </el-table>
      <!-- 选手管理分页 -->
      <div v-if="activeTab !== 'audit'" class="block">
        <el-pagination
          background
          :page-sizes="[20, 40, 60, 80]"
          :page-size="userFrom.limit"
          :current-page="userFrom.page"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData.total"
          @size-change="handleSizeChange"
          @current-change="pageChange"
        />
      </div>

      <!-- 审核选手认证分页 -->
      <div v-if="activeTab === 'audit'" class="block">
        <el-pagination
          background
          :page-sizes="[10, 20, 50, 100]"
          :page-size="auditListPram.limit"
          :current-page="auditListPram.page"
          layout="total, sizes, prev, pager, next, jumper"
          :total="auditTableData.total"
          @size-change="handleAuditSizeChange"
          @current-change="handleAuditPageChange"
        />
      </div>
    </el-card>
    <div class="card_abs" v-show="card_select_show" :style="{ top: collapse ? 570 + 'px' : 270 + 'px' }">
      <template>
        <div class="cell_ht">
          <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange"
            >全选</el-checkbox
          >
          <el-button type="text" @click="checkSave()">保存</el-button>
        </div>
        <el-checkbox-group v-model="checkedCities" @change="handleCheckedCitiesChange">
          <el-checkbox v-for="item in columnData" :label="item" :key="item" class="check_cell">{{ item }}</el-checkbox>
        </el-checkbox-group>
      </template>
    </div>
    <!--修改推广人-->
    <el-dialog title="修改推广人" :visible.sync="extensionVisible" width="540px" :before-close="handleCloseExtension">
      <el-form
        class="formExtension mt20"
        ref="formExtension"
        :model="formExtension"
        :rules="ruleInline"
        label-width="70px"
        @submit.native.prevent
        v-loading="loading"
      >
        <el-form-item label="选择用户:" prop="image">
          <div class="upLoadPicBox" @click="modalPicTap">
            <div v-if="selectedUser.image" class="acea-row">
              <img class="pictrue" :src="selectedUser.image" />
              <span>{{ selectedUser.nickname }}</span>
            </div>
            <div v-else class="upLoad">
              <i class="el-icon-camera cameraIconfont" />
            </div>
          </div>
        </el-form-item>
      </el-form>
      <span slot="footer">
        <el-button @click="extensionVisible = false">取消</el-button>
        <el-button type="primary" @click="onSubExtension('formExtension')">确定</el-button>
      </span>
    </el-dialog>
    <!--用户列表-->
    <el-dialog class="big-dialog" title="推广员列表" :visible.sync="userVisible" width="900px">
      <user-list v-if="userVisible" @getTemplateRow="getTemplateRow"></user-list>
      <!-- <span slot="footer">
        <el-button @click="userVisible = false">取 消</el-button>
        <el-button type="primary" @click="userVisible = false">确 定</el-button>
      </span> -->
    </el-dialog>
    <!--批量设置-->
    <el-dialog
      :title="isBatch ? '批量添加标签' : '设置标签'"
      :visible.sync="dialogVisible"
      width="540px"
      :before-close="handleClose"
    >
      <el-form
        :model="dynamicValidateForm"
        ref="dynamicValidateFormRef"
        label-width="75px"
        class="demo-dynamic"
        v-loading="loading"
      >
        <el-form-item
          prop="groupId"
          label="用户标签："
          :rules="[{ required: true, message: '请选择用户标签', trigger: 'change' }]"
        >
          <el-select v-model="dynamicValidateForm.groupId" placeholder="请选择标签" filterable multiple>
            <el-option :value="item.id" v-for="(item, index) in labelLists" :key="index" :label="item.name"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button
          type="primary"
          v-debounceClick="
            () => {
              submitForm('dynamicValidateFormRef');
            }
          "
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <!--编辑-->
    <el-dialog title="编辑" :visible.sync="visible" width="900px">
      <edit-from v-if="visible" :userInfo="userInfo" @resetForm="resetForm" class="dialog-bottom"></edit-from>
    </el-dialog>
    <!--积分余额-->
    <el-dialog
      :title="type === 'integral' ? '积分' : '余额'"
      :visible.sync="VisiblePoint"
      width="540px"
      :close-on-click-modal="false"
      :before-close="handlePointClose"
    >
      <el-form
        :model="PointValidateForm"
        ref="PointValidateForm"
        label-width="75px"
        class="demo-dynamic"
        v-loading="loadingPoint"
      >
        <el-form-item :label="type === 'integral' ? '积分：' : '余额：'" required>
          <span>{{ type === 'integral' ? userInfo.integral : userInfo.nowMoney }}</span>
        </el-form-item>
        <template v-if="type === 'integral'">
          <el-form-item label="修改积分：" required>
            <el-radio-group v-model="PointValidateForm.operateType">
              <el-radio label="add">增加</el-radio>
              <el-radio label="sub">减少</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="积分：" required>
            <el-input-number
              type="text"
              step-strictly
              v-model.trim="PointValidateForm.integral"
              :min="0"
              :max="999999"
            ></el-input-number>
          </el-form-item>
        </template>
        <template v-else>
          <el-form-item label="修改余额：" required>
            <el-radio-group v-model="PointValidateForm.operateType">
              <el-radio label="add">增加</el-radio>
              <el-radio label="sub">减少</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="余额：" required>
            <el-input-number
              type="text"
              v-model.trim="PointValidateForm.money"
              :precision="2"
              :step="0.1"
              :min="0"
              :max="999999"
            ></el-input-number>
          </el-form-item>
        </template>
      </el-form>
      <span slot="footer">
        <el-button @click="handlePointClose">取 消</el-button>
        <el-button type="primary" :loading="loadingBtn" @click="submitPointForm('PointValidateForm')">确 定</el-button>
      </span>
    </el-dialog>
    <!--用户详情-->
    <detail-Player :userDetailData="userDetailData" ref="userDetailFrom"></detail-Player>
    <!-- 选择优惠券 -->
    <el-dialog v-if="visibleCoupon" title="优惠券列表" :visible.sync="visibleCoupon" width="1000px">
      <coupon-List v-if="visibleCoupon" ref="couponList" :checkedIds="checkedIds" @sendSuccess="sendSuccess" />
    </el-dialog>
    <!-- 赠送会员卡 -->
    <gift-to-members
      v-if="dialogVisibleMember"
      :tableDataMember="tableDataMember"
      :dialogVisibleMember="dialogVisibleMember"
      ref="giftMembersRef"
      :checkedIds="checkeduIds.toString()"
      @handlerSuccessSubmit="handlerSuccessSubmit"
      @handlerSuccessClose="handlerSuccessSubmit"
    ></gift-to-members>

    <!-- 审核抽屉 -->
    <el-drawer
      :visible.sync="auditDialogVisible"
      :direction="direction"
      custom-class="demo-drawer"
      size="1000px"
      ref="drawer"
      class="infoBox"
      @close="closeAuditDialog"
    >
      <div v-loading="auditLoading" v-if="auditDialogVisible">
        <div class="detailHead">
          <div class="acea-row row-between headerBox">
            <div class="full">
              <div class="order_icon"><span class="iconfont icon-shenhe"></span></div>
              <div class="text">
                <div class="title">选手认证审核</div>
                <div>
                  <span class="mr20"
                    >审核状态：<span class="color-warning">{{ getAuditStatusText(auditForm.checkStatus) }}</span></span
                  >
                </div>
              </div>
            </div>
            <div class="acea-row justify-content">
              <el-button
                @click="submitAuditReject"
                style="margin-left: 0"
                :loading="auditLoading"
              >{{ auditLoading ? '提交中 ...' : '审核拒绝' }}</el-button>
              <el-button
                type="primary"
                @click="submitAuditPass"
                :loading="auditLoading"
              >{{ auditLoading ? '提交中 ...' : '审核通过' }}</el-button>
            </div>
          </div>
        </div>
        <el-tabs type="border-card" v-model="currentTab">
          <!-- 基础信息 -->
          <el-tab-pane label="基础信息" name="0">
            <div class="detailSection">
              <ul class="list mt-16">
                <li class="item">
                  <div class="tips">ID：</div>
                  <div class="value">{{ auditForm.id | filterEmpty }}</div>
                </li>
                <li class="item">
                  <div class="tips">用户ID：</div>
                  <div class="value">{{ auditForm.eUserId | filterEmpty }}</div>
                </li>
                <li class="item">
                  <div class="tips">姓名：</div>
                  <div class="value">{{ auditForm.name | filterEmpty }}</div>
                </li>
                <li class="item">
                  <div class="tips">手机号：</div>
                  <div class="value">{{ auditForm.phoneNumber | filterEmpty }}</div>
                </li>
                <li class="item">
                  <div class="tips">邮箱：</div>
                  <div class="value">{{ auditForm.email | filterEmpty }}</div>
                </li>
                <li class="item">
                  <div class="tips">身份证号：</div>
                  <div class="value">{{ auditForm.idCard | filterEmpty }}</div>
                </li>
                <li class="item">
                  <div class="tips">企业名称：</div>
                  <div class="value">{{ auditForm.companyName | filterEmpty }}</div>
                </li>
                <li class="item">
                  <div class="tips">学校名称：</div>
                  <div class="value">{{ auditForm.schoolName | filterEmpty }}</div>
                </li>
                <li class="item">
                  <div class="tips">认证类型：</div>
                  <div class="value">{{ getApplyTypeText(auditForm.applyType) }}</div>
                </li>
                <li class="item">
                  <div class="tips">报名时间：</div>
                  <div class="value">{{ auditForm.applyTime | filterEmpty }}</div>
                </li>
                <li class="item">
                  <div class="tips">创建时间：</div>
                  <div class="value">{{ auditForm.createTime | filterEmpty }}</div>
                </li>
                <li class="item">
                  <div class="tips">更新时间：</div>
                  <div class="value">{{ auditForm.updateTime | filterEmpty }}</div>
                </li>
              </ul>
              <div class="list" style="display: block">
                <div class="item">
                  <div class="tips">说明：</div>
                  <div class="value">{{ auditForm.remark | filterEmpty }}</div>
                </div>
              </div>
            </div>
          </el-tab-pane>

          <!-- 文件信息 -->
          <el-tab-pane label="文件信息" name="2">
            <div class="detailSection">
              <ul class="list mt-16">
                <li class="item">
                  <div class="tips">身份证正面：</div>
                  <div class="value">
                    <el-image
                      v-if="auditForm.idCardFront"
                      :src="auditForm.idCardFront"
                      style="max-width: 200px; max-height: 150px"
                      :preview-src-list="[auditForm.idCardFront]"
                    />
                    <span v-else class="text-muted">暂无图片</span>
                  </div>
                </li>
                <li class="item">
                  <div class="tips">身份证反面：</div>
                  <div class="value">
                    <el-image
                      v-if="auditForm.idCardEnd"
                      :src="auditForm.idCardEnd"
                      style="max-width: 200px; max-height: 150px"
                      :preview-src-list="[auditForm.idCardEnd]"
                    />
                    <span v-else class="text-muted">暂无图片</span>
                  </div>
                </li>
                <li class="item">
                  <div class="tips">营业执照：</div>
                  <div class="value">
                    <el-image
                      v-if="auditForm.businessLicense"
                      :src="auditForm.businessLicense"
                      style="max-width: 200px; max-height: 150px"
                      :preview-src-list="[auditForm.businessLicense]"
                    />
                    <span v-else class="text-muted">暂无图片</span>
                  </div>
                </li>
                <li class="item">
                  <div class="tips">授权书：</div>
                  <div class="value">
                    <el-image
                      v-if="auditForm.authorization"
                      :src="auditForm.authorization"
                      style="max-width: 200px; max-height: 150px"
                      :preview-src-list="[auditForm.authorization]"
                    />
                    <span v-else class="text-muted">暂无图片</span>
                  </div>
                </li>
                <li class="item">
                  <div class="tips">学生证：</div>
                  <div class="value">
                    <el-image
                      v-if="auditForm.studentCard"
                      :src="auditForm.studentCard"
                      style="max-width: 200px; max-height: 150px"
                      :preview-src-list="[auditForm.studentCard]"
                    />
                    <span v-else class="text-muted">暂无图片</span>
                  </div>
                </li>
              </ul>
            </div>
          </el-tab-pane>
        </el-tabs>
      </div>
    </el-drawer>

    <!-- 详情对话框 -->
    <el-dialog :visible.sync="detailDialogVisible" title="申请详情" width="800px">
      <el-descriptions :column="2" border>
        <el-descriptions-item label="姓名">{{ detailData.name }}</el-descriptions-item>
        <el-descriptions-item label="手机号">{{ detailData.phoneNumber }}</el-descriptions-item>
        <el-descriptions-item label="邮箱">{{ detailData.email }}</el-descriptions-item>
        <el-descriptions-item label="身份证号">{{ detailData.idCard }}</el-descriptions-item>
        <el-descriptions-item label="企业名称">{{ detailData.companyName }}</el-descriptions-item>
        <el-descriptions-item label="认证类型">
          <el-tag :type="getApplyTypeTagType(detailData.applyType)">
            {{ getApplyTypeText(detailData.applyType) }}
          </el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="报名时间">{{ detailData.applyTime }}</el-descriptions-item>
        <el-descriptions-item label="审核状态">
          <el-tag :type="getAuditStatusTagType(detailData.checkStatus)">
            {{ getAuditStatusText(detailData.checkStatus) }}
          </el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="审核说明" :span="2" v-if="detailData.checkRemark">{{
          detailData.checkRemark
        }}</el-descriptions-item>
        <el-descriptions-item label="创建时间" v-if="detailData.createTime">{{
          detailData.createTime
        }}</el-descriptions-item>
      </el-descriptions>
    </el-dialog>
  </div>
</template>

<script>
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
import {
  userListApi,
  tagAllListApi,
  tagPiApi,
  foundsApi,
  updateSpreadApi,
  balanceApi,
  memberCardListApi,
  playerListApi,
} from '@/api/user';
import request from '@/utils/request'; // HTTP请求
import { filterEmpty } from '@/filters'; // 过滤器
import { spreadClearApi } from '@/api/distribution';
import detailPlayer from '@/components/detailPlayer';
import editFrom from '../list/edit';
import levelEdit from '../list/level';
import userList from '@/components/userList';
import couponList from '../components/couponList';
import giftToMembers from '../components/giftToMembers';
import { checkPermi } from '@/utils/permission'; // 权限判断函数
import { Debounce } from '@/utils/validate';
import { handleDeleteTable } from '@/libs/public';
export default {
  name: 'PlayerIndex',
  components: { editFrom, userList, levelEdit, couponList, giftToMembers, detailPlayer },
  filters: {
    filterEmpty,
  },
  data() {
    return {
      activeTab: 'all', // 当前激活的标签页
      userDetailData: {},
      // 审核选手认证相关数据
      auditListLoading: false,
      auditTableData: {
        data: [],
        total: 0,
      },
      auditListPram: {
        name: '',
        phoneNumber: '',
        email: '',
        checkStatus: null,
        applyTypeList: null,
        page: 1,
        limit: 20,
      },
      auditSearchForm: {
        name: '',
        phoneNumber: '',
        email: '',
        checkStatus: null,
        applyTypeList: null,
      },
      // 审核对话框
      auditDialogVisible: false,
      auditLoading: false,
      auditForm: {
        id: null,
        competitionId: null,
        name: '',
        phoneNumber: '',
        email: '',
        idCard: '',
        companyName: '',
        applyType: null,
        competitionName: '',
        applyTime: '',
        remark: '',
        checkStatus: null,
        checkRemark: '',
        fileUrl: '',
        idCardFront: '',
        idCardEnd: '',
        businessLicense: '',
        authorization: '',
        studentCard: '',
        eUserId: null,
        isApply: null,
        createTime: '',
        updateTime: '',
        isDel: false,
        schoolName: '',
      },
      // 详情对话框
      detailDialogVisible: false,
      detailData: {},
      // 审核抽屉相关
      direction: 'rtl',
      currentTab: '0',
      registerTypeList: [
        {
          value: 'wechat',
          label: '公众号',
        },
        {
          value: 'routine',
          label: '小程序',
        },
        {
          value: 'h5',
          label: 'H5',
        },
        {
          value: 'iosWx',
          label: '微信ios',
        },
        {
          value: 'androidWx',
          label: '微信安卓',
        },
        {
          value: 'ios',
          label: 'ios',
        },
      ],
      auditStatusList: [
        {
          value: '0',
          label: '待审核',
        },
        {
          value: '1',
          label: '审核通过',
        },
        {
          value: '2',
          label: '审核失败',
        },
        {
          value: '3',
          label: '平台关闭',
        },
      ],
      // 添加选手认证类型选项
      applyTypesList: [
        {
          value: '0,1,2,3',
          label: '全部',
        },
        {
          value: '0',
          label: '未认证',
        },
        {
          value: '1',
          label: '个人',
        },
        {
          value: '2',
          label: '企业',
        },
        {
          value: '3',
          label: '学生',
        },
        {
          value: '-1',
          label: '原创用户',
        },
      ],
      formExtension: {
        spreadUid: '',
        userId: '',
      },
      selectedUser: {
        image: '',
        nickname: '',
      },
      ruleInline: {},
      extensionVisible: false,
      userVisible: false,
      levelInfo: '',
      pickerOptions: this.$timeOptions,
      loadingBtn: false,
      PointValidateForm: {
        integral: null,
        operateType: 'add',
        uid: '',
        money: null,
      },
      loadingPoint: false,
      VisiblePoint: false,
      visible: false,
      dialogVisible: false,
      levelVisible: false,
      labelData: [],
      selData: [],
      keywords: '',
      labelPosition: 'right',
      collapse: false,
      listLoading: true,
      tableData: {
        data: [],
        total: 0,
      },
      userFrom: {
        page: 1,
        limit: 20,
        playerName: '',
        auditStatus: '',
        applyTypes: '0,1,2,3',
        emailAccount: '',
        phone: '',
        schoolCompany: '',
      },
      grid: {
        xl: 8,
        lg: 12,
        md: 12,
        sm: 24,
        xs: 24,
      },
      labelLists: [],
      selectedData: [],
      timeVal: [],
      dynamicValidateForm: {
        groupId: [],
      },
      loading: false,
      groupIdFrom: [],
      selectionList: [],
      batchName: '',
      uid: 0,
      Visible: false,
      keyNum: 0,
      multipleSelection: [],
      multipleSelectionAll: [],
      idKey: 'id',
      card_select_show: false,
      checkAll: false,
      checkedCities: ['ID', '头像', '姓名', '注册类型', '推荐人', '联系电话', '余额', '积分'],
      columnData: ['ID', '头像', '姓名', '注册类型', '推荐人', '联系电话', '余额', '积分'],
      isIndeterminate: true,
      type: 'integral',
      userInfo: {},
      checkedIds: [],
      selectAllPage: false,
      visibleCoupon: false, //发送优惠券显示
      isBatch: false, //是否是批量
      tableDataMember: [], //会员卡
      dialogVisibleMember: false,
      checkeduIds: '',
    };
  },
  activated() {
    this.getList(1);
  },
  mounted() {
    // 检查URL参数中是否有选手名称，如果有则自动搜索
    if (this.$route.query.playerName) {
      this.userFrom.playerName = this.$route.query.playerName;
      this.activeTab = 'all'; // 切换到全部标签页
      this.userFrom.page = 1;
      if (checkPermi(['platform:user:page:list'])) {
        // 稍微延迟一下执行搜索，确保组件完全加载
        setTimeout(() => {
          this.getList(1);
        }, 100);
      }
    } else {
      // 如果没有URL参数，则执行默认加载
      if (checkPermi(['platform:user:page:list'])) this.getList(1);
    }
    if (checkPermi(['platform:user:tag:all:list'])) this.getTagList();
    if (checkPermi(['platform:paid:member:card:list'])) this.getMemberList();
  },
  methods: {
    checkPermi,
    handleResetSelection() {
      this.handleClearCheckbox();
    },
    sexFilter(status) {
      const statusMap = {
        0: '未知',
        1: '男',
        2: '女',
        3: '保密',
      };
      return statusMap[status];
    },
    //性别
    getSexImage(sex) {
      const iconMap = {
        0: 'unknown.png',
        1: 'man.png',
        2: 'woman.png',
        3: 'unknown.png',
      };
      const imageName = iconMap[sex] || 'unknown.png';
      return require(`@/assets/imgs/${imageName}`);
    },
    //赠送会员
    handleGiftMembers(row) {
      if (!this.multipleSelection.length && !row) return this.$message.warning('请选择用户');
      if (row) {
        this.checkeduIds = row.id;
      } else {
        this.getUserIds();
        this.checkeduIds = this.checkedIds.join(',');
      }
      this.dialogVisibleMember = true;
    },
    handlerSuccessSubmit() {
      this.handleClearCheckbox();
      this.dialogVisibleMember = false;
    },
    //会员卡列表
    async getMemberList() {
      try {
        this.tableDataMember = await memberCardListApi({ type: 1, status: 1 });
      } catch (e) {}
    },
    filterRegisterType(status) {
      const statusMap = {
        wechat: '#FD5ACC',
        routine: '#A277FF',
        h5: '#E8B600',
        iosWx: '#1BBE6B',
        androidWx: '#EF9C20',
        ios: '#1890FF',
      };
      return statusMap[status];
    },
    // 清除
    clearSpread(row) {
      this.$modalSure('解除【' + row.nickname + '】的上级推广人吗').then(() => {
        spreadClearApi(row.id).then((res) => {
          this.$message.success('清除成功');
          this.getList();
        });
      });
    },
    onSubExtension(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          updateSpreadApi(this.formExtension).then((res) => {
            this.$message.success('设置成功');
            this.extensionVisible = false;
            this.getList();
          });
        } else {
          return false;
        }
      });
    },
    getTemplateRow(row) {
      this.formExtension.spreadUid = row.id;
      this.selectedUser = {
        image: row.avatar,
        nickname: row.nickname,
      };
      this.userVisible = false;
    },
    setExtension(row) {
      this.formExtension = {
        spreadUid: '',
        userId: row.id,
      };
      this.selectedUser = {
        image: '',
        nickname: '',
      };
      this.extensionVisible = true;
    },
    handleCloseExtension() {
      this.extensionVisible = false;
      this.selectedUser = {
        image: '',
        nickname: '',
      };
    },
    modalPicTap() {
      this.userVisible = true;
    },
    resetForm() {
      this.visible = false;
    },
    reset(formName) {
      this.userFrom.payCount = '';
      this.userFrom.sex = '';
      this.userFrom.identity = '';
      this.userFrom.registerType = '';
      this.userFrom.page = 1;
      this.userFrom.searchType = 'all';
      this.userFrom.content = '';
      this.userFrom.auditStatus = '';
      this.userFrom.applyTypes = '0,1,2,3';
      this.userFrom.playerName = '';
      this.userFrom.emailAccount = '';
      this.userFrom.phone = '';
      this.userFrom.schoolCompany = '';
      // applyTypes在getList方法中会重新设置为默认值
      this.keywords = '';
      this.labelData = [];
      this.timeVal = [];
      this.getList(1);
    },
    Close() {
      this.Visible = false;
      this.levelVisible = false;
    },
    // 账户详情
    onDetails(id, row) {
      this.$refs.userDetailFrom.getUserDetail(id);
      this.$refs.userDetailFrom.dialogUserDetail = true;
      this.userDetailData = row;
    },
    // 积分余额
    editPoint(row, type) {
      this.uid = row.id;
      this.type = type;
      this.userInfo = row;
      this.VisiblePoint = true;
    },
    // 积分余额
    submitPointForm: Debounce(function (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.PointValidateForm.uid = this.uid;
          this.loadingBtn = true;
          if (this.type === 'integral') {
            foundsApi(this.PointValidateForm)
              .then((res) => {
                this.$message.success('设置成功');
                this.loadingBtn = false;
                this.handlePointClose();
                this.getList();
              })
              .catch(() => {
                this.loadingBtn = false;
              });
          } else {
            balanceApi(this.PointValidateForm)
              .then((res) => {
                this.$message.success('设置成功');
                this.loadingBtn = false;
                this.handlePointClose();
                this.getList();
              })
              .catch(() => {
                this.loadingBtn = false;
              });
          }
        } else {
          return false;
        }
      });
    }),
    // 积分余额
    handlePointClose() {
      this.VisiblePoint = false;
      this.PointValidateForm = {
        integral: null,
        operateType: 'add',
        uid: '',
        money: null,
      };
    },
    editUser(row) {
      this.userInfo = row;
      this.visible = true;
    },
    // 设置用户标签
    submitForm: Debounce(function (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.getUserIds();
          this.loading = true;
          tagPiApi({ tagIds: this.dynamicValidateForm.groupId.join(','), ids: this.checkeduIds })
            .then((res) => {
              this.$message.success('设置成功');
              this.loading = false;
              this.handleClose();
              this.getList();
            })
            .catch(() => {
              this.loading = false;
            });
        } else {
          return false;
        }
      });
    }),
    setBatch(name, row, num) {
      num === 1 ? (this.isBatch = true) : (this.isBatch = false);
      this.batchName = name;
      if (row) {
        this.checkeduIds = row.id;
      } else {
        this.getUserIds();
        this.checkeduIds = this.checkedIds.join(',');
      }

      // if (row) this.checkedIds = row.id;
      //  this.dynamicValidateForm.groupId = ''
      if (this.multipleSelection.length === 0 && !row) return this.$message.warning('请选择要设置的用户');
      this.dialogVisible = true;
      this.$nextTick(() => {
        this.$refs.dynamicValidateFormRef.clearValidate();
      });
    },
    //清除选中
    handleClearCheckbox() {
      this.$refs.table.clearSelection();
      this.multipleSelectionAll = [];
    },
    handleClose() {
      this.handleClearCheckbox();
      this.dialogVisible = false;
      this.$refs.dynamicValidateFormRef.resetFields();
    },
    // 搜索
    userSearchs() {
      this.userFrom.page = 1;
      this.getList();
    },
    // 具体日期
    onchangeTime(e) {
      this.timeVal = e;
      this.userFrom.dateLimit = e ? this.timeVal.join(',') : '';
    },
    //标签列表
    getTagList() {
      tagAllListApi().then((res) => {
        this.labelLists = res;
        localStorage.setItem('tagAllList', JSON.stringify(res));
      });
    },
    // 标签页切换
    handleTabClick() {
      if (this.activeTab === 'audit') {
        this.auditListPram.page = 1;
        this.getAuditList();
      } else {
        this.userFrom.page = 1;
        this.getList();
      }
    },
    // 列表
    getList(num) {
      this.listLoading = true;
      this.userFrom.page = num ? num : this.userFrom.page;
      this.userFrom.tagIds = this.labelData.join(',');
      
      // 根据activeTab设置auditStatus参数
      const params = { 
        applyTypes: this.userFrom.applyTypes || '0,1,2,3', 
        ...this.userFrom 
      };
      
      // 处理学校/企业搜索字段映射
      if (this.userFrom.schoolCompany) {
        // 同时搜索学校名称和企业名称字段
        params.schoolName = this.userFrom.schoolCompany;
        params.companyName = this.userFrom.schoolCompany;
      }
      
      // 处理keywords搜索
      if (this.keywords) {
        params.keywords = this.keywords;
      }
      
      // 如果是待审核标签页，添加auditStatus=1参数
      if (this.activeTab === '1') {
        params.auditStatus = 1;
      }
      
      playerListApi(params)
        .then((res) => {
          this.tableData.data = res.list;
          this.tableData.total = res.total;
          this.$nextTick(function () {
            this.setSelectRow(); // 调用跨页选中方法
          });
          this.listLoading = false;
        })
        .catch(() => {
          this.listLoading = false;
        });
      this.checkedCities = this.$cache.local.has('user_stroge')
        ? this.$cache.local.getJSON('user_stroge')
        : this.checkedCities;
      this.$set(this, 'card_select_show', false);
    },
    // 设置选中的方法
    setSelectRow() {
      if (!this.multipleSelectionAll || this.multipleSelectionAll.length <= 0) {
        return;
      }
      // 标识当前行的唯一键的名称
      const idKey = this.idKey;
      const selectAllIds = [];
      this.multipleSelectionAll.forEach((row) => {
        selectAllIds.push(row[idKey]);
      });
      this.$refs.table.clearSelection();
      for (var i = 0; i < this.tableData.data.length; i++) {
        if (selectAllIds.indexOf(this.tableData.data[i][idKey]) >= 0) {
          // 设置选中，记住table组件需要使用ref="table"
          this.$refs.table.toggleRowSelection(this.tableData.data[i], true);
        }
      }
    },
    // 设置选中的方法
    handleSelectionChange(val) {
      this.multipleSelection = val;
      setTimeout(() => {
        this.$selfUtil.changePageCoreRecordData(
          this.multipleSelectionAll,
          this.multipleSelection,
          this.tableData.data,
          (e) => {
            this.multipleSelectionAll = e;
          },
        );
      }, 50);
    },
    pageChange(page) {
      this.$selfUtil.changePageCoreRecordData(
        this.multipleSelectionAll,
        this.multipleSelection,
        this.tableData.data,
        (e) => {
          this.multipleSelectionAll = e;
        },
      );
      this.userFrom.page = page;
      this.getList();
    },
    handleSizeChange(val) {
      this.$selfUtil.changePageCoreRecordData(
        this.multipleSelectionAll,
        this.multipleSelection,
        this.tableData.data,
        (e) => {
          this.multipleSelectionAll = e;
        },
      );
      this.userFrom.limit = val;
      this.getList(1);
    },
    // 删除
    handleDelete(id, idx) {
      this.$modalSure().then(() => {
        productDeleteApi(id).then(() => {
          this.$message.success('删除成功');
          handleDeleteTable(this.tableData.data.length, this.userFrom);
          this.getList();
        });
      });
    },
    onchangeIsShow(row) {
      row.isShow
        ? putOnShellApi(row.id)
            .then(() => {
              this.$message.success('上架成功');
              this.getList();
            })
            .catch(() => {
              row.isShow = !row.isShow;
            })
        : offShellApi(row.id)
            .then(() => {
              this.$message.success('下架成功');
              this.getList();
            })
            .catch(() => {
              row.isShow = !row.isShow;
            });
    },
    handleAddItem() {
      if (this.card_select_show) {
        this.$set(this, 'card_select_show', false);
      } else if (!this.card_select_show) {
        this.$set(this, 'card_select_show', true);
      }
    },
    handleCheckAllChange(val) {
      this.checkedCities = val ? this.columnData : [];
      this.isIndeterminate = false;
    },
    handleCheckedCitiesChange(value) {
      let checkedCount = value.length;
      this.checkAll = checkedCount === this.columnData.length;
      this.isIndeterminate = checkedCount > 0 && checkedCount < this.columnData.length;
    },
    checkSave() {
      this.card_select_show = false;
      this.$modal.loading('正在保存到本地，请稍候...');
      this.$cache.local.setJSON('user_stroge', this.checkedCities);
      setTimeout(this.$modal.closeLoading(), 1000);
    },
    // 获取批量用户ids
    getUserIds() {
      const data = [];
      this.multipleSelectionAll.map((item) => {
        data.push(item.id);
      });
      this.checkedIds = data;
    },
    //发送优惠券
    sendCoupon() {
      if (this.multipleSelection.length > 0) {
        this.getUserIds();
        this.visibleCoupon = true;
      } else {
        this.$message.warning('请选择用户');
      }
    },
    sendSuccess() {
      this.handleClearCheckbox();
      this.visibleCoupon = false;
    },

    // ========== 审核选手认证相关方法 ==========
    
    // 获取审核列表数据
    getAuditList(num) {
      this.auditListLoading = true;
      this.auditListPram.page = num ? num : this.auditListPram.page;
      
      const apiUrls = ['/admin/apply/audit/page/list', '/admin/apply/audit/list', '/admin/apply/list'];
      this.tryAuditApiCall(apiUrls, 0, this.auditListPram);
    },

    // 尝试审核API调用
    tryAuditApiCall(apiUrls, index, pram) {
      if (index >= apiUrls.length) {
        console.error('所有审核API接口都调用失败，使用模拟数据');
        this.loadAuditMockData();
        return;
      }

      const apiUrl = apiUrls[index];
      console.log(`尝试调用审核API: ${apiUrl}`);

      request
        .get(apiUrl, {
          params: {
            page: pram.page,
            limit: pram.limit,
            name: pram.name,
            phoneNumber: pram.phoneNumber,
            email: pram.email,
            checkStatus: pram.checkStatus,
            applyTypeList: pram.applyTypeList ? pram.applyTypeList : '1,2,3',
          },
        })
        .then((res) => {
          console.log(`审核API ${apiUrl} 响应:`, res);
          this.auditTableData = {
            data: res.list || res.data?.list || [],
            total: res.total || res.data?.total || 0,
          };
          this.auditListLoading = false;
        })
        .catch((err) => {
          console.error(`审核API ${apiUrl} 调用失败:`, err);
          this.tryAuditApiCall(apiUrls, index + 1, pram);
        });
    },

    // 加载审核模拟数据
    loadAuditMockData() {
      console.log('加载审核模拟数据');
      this.auditTableData = {
        data: [
          {
            id: 1,
            euserId: 1001,
            name: '张三',
            phoneNumber: '13800138001',
            email: 'zhangsan@example.com',
            idCard: '110101199001011234',
            companyName: '测试公司',
            schoolName: '',
            applyType: 1,
            checkStatus: null,
            checkRemark: '',
            applyTime: '2024-01-01 10:00:00',
            createTime: '2024-01-01 10:00:00',
          },
          {
            id: 2,
            euserId: 1002,
            name: '李四',
            phoneNumber: '13800138002',
            email: 'lisi@example.com',
            idCard: '110101199002021234',
            companyName: '创意公司',
            schoolName: '',
            applyType: 2,
            checkStatus: 1,
            checkRemark: '审核通过',
            applyTime: '2024-01-02 10:00:00',
            createTime: '2024-01-02 10:00:00',
          },
        ],
        total: 2,
      };
      this.auditListLoading = false;
    },

    // 获取认证类型文本
    getApplyTypeText(applyType) {
      const typeMap = {
        1: '个人',
        2: '企业',
        3: '学生',
      };
      return typeMap[applyType] || '未认证';
    },

    // 获取认证类型标签类型
    getApplyTypeTagType(applyType) {
      const typeMap = {
        1: 'primary', // 个人 - 蓝色
        2: 'success', // 企业 - 绿色
        3: 'warning', // 学生 - 橙色
      };
      return typeMap[applyType] || 'danger';
    },

    // 获取审核状态文本
    getAuditStatusText(status) {
      const statusMap = {
        null: '待审核',
        1: '审核通过',
        0: '审核拒绝',
      };
      return statusMap[status] || '未审核';
    },

    // 获取审核状态标签类型
    getAuditStatusTagType(status) {
      const statusMap = {
        null: 'warning', // 待审核
        1: 'success', // 审核通过
        0: 'danger', // 审核拒绝
      };
      return statusMap[status] || 'info';
    },

    // 判断审核是否已完成
    isAuditCompleted(status) {
      return status === 1 || status === 0;
    },

    // 审核详情
    handleAuditDetail(row) {
      request
        .get(`/admin/apply/audit/detail/${row.id}`)
        .then((res) => {
          console.log('获取审核详情成功:', res);
          this.detailData = res.data || res;
          this.detailDialogVisible = true;
        })
        .catch((err) => {
          console.error('获取审核详情失败:', err);
          this.$message.error('获取详情失败，请稍后重试');
        });
    },

    // 处理审核
    handleAudit(row) {
      if (this.isAuditCompleted(row.checkStatus)) {
        this.$message.warning('该申请已完成审核，无法重复操作');
        return;
      }

      this.auditForm = {
        id: row.id,
        competitionId: row.competitionId,
        name: row.name,
        phoneNumber: row.phoneNumber,
        email: row.email,
        idCard: row.idCard,
        companyName: row.companyName,
        applyType: row.applyType,
        competitionName: row.competitionName,
        applyTime: row.applyTime,
        remark: row.remark,
        checkStatus: row.checkStatus,
        checkRemark: row.checkRemark || '',
        fileUrl: row.fileUrl || '',
        idCardFront: row.idCardFront || '',
        idCardEnd: row.idCardEnd || '',
        businessLicense: row.businessLicense || '',
        authorization: row.authorization || '',
        studentCard: row.studentCard || '',
        eUserId: row.eUserId,
        isApply: row.isApply,
        createTime: row.createTime || '',
        updateTime: row.updateTime || '',
        isDel: row.isDel || false,
        schoolName: row.schoolName || '',
      };
      this.currentTab = '0';
      this.auditDialogVisible = true;
    },

    // 审核分页大小改变
    handleAuditSizeChange(val) {
      this.auditListPram.limit = val;
      this.getAuditList();
    },

    // 审核当前页改变
    handleAuditPageChange(val) {
      this.auditListPram.page = val;
      this.getAuditList();
    },

    // 提交审核
    submitAudit() {
      if (!this.auditForm.id) {
        this.$message.error('缺少审核记录ID');
        return;
      }

      if (this.auditForm.checkStatus === null || this.auditForm.checkStatus === undefined) {
        this.$message.error('请选择审核结果');
        return;
      }

      this.auditLoading = true;

      const apiUrl = this.auditForm.checkStatus === 1 ? '/admin/apply/audit/pass' : '/admin/apply/audit/reject';
      const requestData = {
        id: this.auditForm.id,
        isApply: this.auditForm.checkStatus === 1 ? 2 : 3,
      };

      if (this.auditForm.checkStatus === 0 && this.auditForm.checkRemark) {
        requestData.checkRemark = this.auditForm.checkRemark;
      }

      request
        .post(apiUrl, requestData)
        .then((res) => {
          if (res === null || res === undefined || res.code === 200 || res.code === '200' || res.status === 200) {
            this.$message.success('审核完成');
            this.closeAuditDialog();
            this.getAuditList();
          } else {
            this.$message.error(res.message || res.msg || '审核失败');
          }
          this.auditLoading = false;
        })
        .catch((err) => {
          console.error('审核API调用失败:', err);
          this.$message.error('审核失败，请稍后重试');
          this.auditLoading = false;
        });
    },

    // 审核通过
    submitAuditPass() {
      this.$modalSure('确定要通过该申请吗？')
        .then(() => {
          this.auditForm.checkStatus = 1;
          this.submitAudit();
        })
        .catch(() => {
          console.log('用户取消审核通过');
        });
    },

    // 审核拒绝
    submitAuditReject() {
      this.$modalPrompt('textarea', '请输入拒绝原因', '')
        .then((reason) => {
          const reasonText = typeof reason === 'string' ? reason : reason && reason.value ? reason.value : '';
          if (!reasonText || reasonText.trim() === '') {
            this.$message.warning('拒绝原因不能为空');
            return;
          }
          this.auditForm.checkRemark = reasonText.trim();
          this.auditForm.checkStatus = 0;
          this.submitAudit();
        })
        .catch(() => {
          console.log('用户取消输入拒绝原因');
        });
    },

    // 关闭审核对话框
    closeAuditDialog() {
      this.auditDialogVisible = false;
      this.auditForm = {
        id: null,
        competitionId: null,
        name: '',
        phoneNumber: '',
        email: '',
        idCard: '',
        companyName: '',
        applyType: null,
        competitionName: '',
        applyTime: '',
        remark: '',
        checkStatus: null,
        checkRemark: '',
        fileUrl: '',
        idCardFront: '',
        idCardEnd: '',
        businessLicense: '',
        authorization: '',
        studentCard: '',
        eUserId: null,
        isApply: null,
        createTime: '',
        updateTime: '',
        isDel: false,
        schoolName: '',
      };
    },
  },
};
</script>

<style scoped lang="scss">
.sexImg,
img {
  width: 16px !important;
  height: 16px !important;
  margin-left: 2px;
}
::v-deep .el-table__cell:nth-child(2) .cell {
  padding-left: 14px;
  padding-right: 14px;
}

.red {
  color: #ed4014;
}

.el-icon-arrow-down {
  font-size: 12px;
}

.text-right {
  text-align: right;
}

.demo-table-expand {
  font-size: 0;
}

.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}

.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 33.33%;
}

.seachTiele {
  line-height: 30px;
}

.container {
  min-width: 821px;

  ::v-deepel-form-item {
    width: 100%;
  }

  ::v-deepel-form-item__content {
    width: 72%;
  }
}

.ivu-ml-8 {
  color: var(--prev-color-primary);
}

.btn_bt {
  border-top: 1px dashed #ccc;
  padding-top: 20px;
}

.relative {
  position: relative;
}

.card_abs {
  position: absolute;
  padding-bottom: 15px;
  right: 40px;
  width: 200px;
  background: #fff;
  z-index: 99999;
  box-shadow: 0px 0px 14px 0px rgba(0, 0, 0, 0.1);
}

.cell_ht {
  height: 50px;
  padding: 15px 20px;
  box-sizing: border-box;
  border-bottom: 1px solid #eeeeee;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.check_cell {
  width: 100%;
  padding: 15px 20px 0;
}

::v-deep .el-checkbox__input.is-checked + .el-checkbox__label {
  color: #606266;
}

.userbtn {
  position: absolute;
  right: 0;
}

::v-deep.el-tag {
  color: #fff !important;
}

.search-form {
  display: flex;
  justify-content: space-between;

  .search-form-box {
    display: flex;
    flex-wrap: wrap;
    flex: 1;
  }
}

.search-form-sub {
  display: flex;
}

::v-deep.el-select {
  width: 100%;
}

::v-deep .el-tag {
  border: none;
}

::v-deep .el-tag--small {
  line-height: 24px;
}

::v-deep .el-dialog__title {
  font-weight: 600 !important;
}

::v-deep .el-dialog__body {
  padding-top: 20px !important;
}

.list-tabs {
  margin-bottom: 20px;
}

/* 审核抽屉样式 */
.infoBox {
  .detailHead {
    padding: 20px;
    border-bottom: 1px solid #e6e6e6;
    background: #f8f9fa;

    .headerBox {
      align-items: center;

      .order_icon {
        width: 50px;
        height: 50px;
        background: #409eff;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-right: 15px;

        .iconfont {
          color: #fff;
          font-size: 24px;
        }
      }

      .text {
        flex: 1;

        .title {
          font-size: 18px;
          font-weight: bold;
          color: #333;
          margin-bottom: 8px;
        }

        .color-warning {
          color: #e6a23c;
          font-weight: bold;
        }
      }
    }
  }

  .detailSection {
    padding: 20px;

    .list {
      .item {
        display: flex;
        margin-bottom: 15px;
        align-items: flex-start;

        .tips {
          width: 120px;
          color: #666;
          font-weight: 500;
          flex-shrink: 0;
        }

        .value {
          flex: 1;
          color: #333;
          word-break: break-all;
        }
      }
    }
  }
}

.acea-row {
  display: flex;
  align-items: center;

  &.row-between {
    justify-content: space-between;
  }

  &.justify-content {
    gap: 10px;
  }
}

.mr20 {
  margin-right: 20px;
}

.mt-16 {
  margin-top: 16px;
}

.text-muted {
  color: #999;
  font-size: 12px;
}

// 置灰链接样式
.disabled-link {
  color: #c0c4cc !important;
  text-decoration: none !important;

  &:hover {
    color: #c0c4cc !important;
    text-decoration: none !important;
  }
}

// 审核标签页的标签样式修复
::v-deep .el-table .el-tag {
  color: initial !important;
  border: 1px solid transparent !important;
  
  &.el-tag--primary {
    color: #fff !important;
    background-color: #409eff !important;
    border-color: #409eff !important;
  }
  
  &.el-tag--success {
    color: #fff !important;
    background-color: #67c23a !important;
    border-color: #67c23a !important;
  }
  
  &.el-tag--warning {
    color: #fff !important;
    background-color: #e6a23c !important;
    border-color: #e6a23c !important;
  }
  
  &.el-tag--danger {
    color: #fff !important;
    background-color: #f56c6c !important;
    border-color: #f56c6c !important;
  }
  
  &.el-tag--info {
    color: #fff !important;
    background-color: #909399 !important;
    border-color: #909399 !important;
  }
}

// 详情对话框中的标签样式
::v-deep .el-dialog .el-tag {
  color: initial !important;
  border: 1px solid transparent !important;
  
  &.el-tag--primary {
    color: #fff !important;
    background-color: #409eff !important;
    border-color: #409eff !important;
  }
  
  &.el-tag--success {
    color: #fff !important;
    background-color: #67c23a !important;
    border-color: #67c23a !important;
  }
  
  &.el-tag--warning {
    color: #fff !important;
    background-color: #e6a23c !important;
    border-color: #e6a23c !important;
  }
  
  &.el-tag--danger {
    color: #fff !important;
    background-color: #f56c6c !important;
    border-color: #f56c6c !important;
  }
  
  &.el-tag--info {
    color: #fff !important;
    background-color: #909399 !important;
    border-color: #909399 !important;
  }
}
</style>
